unsigned int newbitcount(unsigned int x);
unsigned int oldbitcount(unsigned int x);
void shotgunPrintUint(const char name[], unsigned int in);

#include <stdio.h>
int main()
{
  for (int i=0; i < 0xffffffff; i++)
  {
    printf("%d\n",oldbitcount(i));
  }
  return 0;
} 

/* bitcount:  count 1 bits in x */
unsigned int oldbitcount(unsigned int x)
{
  int b;
  for (b = 0; x != 0; x >>= 1)
      if (x & 01)
           b++;
  return b;
}

/* bitcount:  count 1 bits in x */
unsigned int newbitcount(unsigned int x)
{
  int b=0;
  unsigned int y = x;
  for (;y!=0;)
    {
	 y &= (y-1);
      b++;
    }
  return b; 
}

/** 
caution if you printf, padded with 0's, a hex number of exactly 0 it will print
as 0000000000 not 0x00000000
*/
/**
   drop me in if you don't want to use a debugger like GDB to shotgun-debug
   print the value of a uint
 */
void shotgunPrintUint(const char name[], unsigned int in)
{
  printf(name,23423);
  printf("\t\t: %0#10x \n",in);
  return;
}
